#include "zuc_nml_io_commu.hh"
#include "cms.hh"
void UhiData_update(CMS* cms, UhiData* x)
{
    cms->update(x->dir);
    cms->update(x->pulses);
    cms->update(x->speed);
}
void FuncIOMap_update(CMS* cms, FuncIOMap* x)
{
    cms->update(x->task_run_di.type);
    cms->update(x->task_run_di.index);
    cms->update(x->task_pause_di.type);
    cms->update(x->task_pause_di.index);
    cms->update(x->task_resume_di.type);
    cms->update(x->task_resume_di.index);
    cms->update(x->task_stop_di.type);
    cms->update(x->task_stop_di.index);
    cms->update(x->power_on_di.type);
    cms->update(x->power_on_di.index);
    cms->update(x->power_off_di.type);
    cms->update(x->power_off_di.index);
    cms->update(x->servo_enable_di.type);
    cms->update(x->servo_enable_di.index);
    cms->update(x->servo_disable_di.type);
    cms->update(x->servo_disable_di.index);
    cms->update(x->back_to_inipos_di.type);
    cms->update(x->back_to_inipos_di.index);
    cms->update(x->stop_mode_di.type);
    cms->update(x->stop_mode_di.index);
    cms->update(x->percentage_mode_level1_di.type);
    cms->update(x->percentage_mode_level1_di.index);
    cms->update(x->percentage_mode_level2_di.type);
    cms->update(x->percentage_mode_level2_di.index);
    cms->update(x->clear_error_di.type);
    cms->update(x->clear_error_di.index);  //
    cms->update(x->drag_mode_di.type);
    cms->update(x->drag_mode_di.index);
    cms->update(x->drag_mode_disable_di.type);
    cms->update(x->drag_mode_disable_di.index);
    for (int i = 0; i < 4; i++)
    {
        cms->update(x->task_idle_do[i].type);
        cms->update(x->task_idle_do[i].index);

        cms->update(x->task_paused_do[i].type);
        cms->update(x->task_paused_do[i].index);

        cms->update(x->task_running_do[i].type);
        cms->update(x->task_running_do[i].index);

        cms->update(x->stat_fault_do[i].type);
        cms->update(x->stat_fault_do[i].index);

        cms->update(x->stat_poweron_do[i].type);
        cms->update(x->stat_poweron_do[i].index);

        cms->update(x->stat_enabled_do[i].type);
        cms->update(x->stat_enabled_do[i].index);

        cms->update(x->stat_motion_do[i].type);
        cms->update(x->stat_motion_do[i].index);

        cms->update(x->stat_static_do[i].type);
        cms->update(x->stat_static_do[i].index);

        cms->update(x->stat_boot_do[i].type);
        cms->update(x->stat_boot_do[i].index);

        cms->update(x->stat_emergency_stop_do[i].type);
        cms->update(x->stat_emergency_stop_do[i].index);

        cms->update(x->stat_percentage_mode_level2_do[i].type);
        cms->update(x->stat_percentage_mode_level2_do[i].index);

        cms->update(x->stat_sys_protective_stop_do[i].type);
        cms->update(x->stat_sys_protective_stop_do[i].index);

        cms->update(x->stat_initial_pose_do[i].type);
        cms->update(x->stat_initial_pose_do[i].index);

        cms->update(x->stat_percentage_mode_level1_do[i].type);
        cms->update(x->stat_percentage_mode_level1_do[i].index);

        cms->update(x->stat_drag_mode_do[i].type);
        cms->update(x->stat_drag_mode_do[i].index);

        cms->update(x->stat_collision_mode_do[i].type);
        cms->update(x->stat_collision_mode_do[i].index);

        cms->update(x->stat_manual_mode_do[i].type);
        cms->update(x->stat_manual_mode_do[i].index);

        cms->update(x->stat_auto_mode_do[i].type);
        cms->update(x->stat_auto_mode_do[i].index);
    }
}

void FuncIOReq_update(CMS* cms, Func_IO_Req_t* x)
{
    cms->update(x->program_stop_req);
    cms->update(x->power_off_req);
    cms->update(x->servo_disable_req);
    cms->update(x->program_pause_req);
}
void ZUC_IO_STAT::update(CMS* cms)
{
    extio.update(cms);
    cms->update(synch_di, ZUCMOT_MAX_DIO);
    cms->update(synch_do, ZUCMOT_MAX_DIO);
    cms->update(analog_input, ZUCMOT_MAX_AIO);
    cms->update(analog_output, ZUCMOT_MAX_AIO);

    cms->update(synch_mb_slave_di, ZUCMOT_MAX_MODBUS_DIO);
    cms->update(synch_pn_dev_di, ZUCMOT_MAX_PNDev_DIO);
    cms->update(synch_eip_adpt_di, ZUCMOT_MAX_EIP_DIO);
    cms->update(synch_eip_in, 492);
    cms->update(synch_eip_out, 492);
    cms->update(synch_mb_slave_do, ZUCMOT_MAX_MODBUS_DIO);
    cms->update(synch_pn_dev_do, ZUCMOT_MAX_PNDev_DIO);
    cms->update(synch_eip_adpt_do, ZUCMOT_MAX_EIP_DIO);

    cms->update(analog_mb_slave_input, ZUCMOT_MAX_MODBUS_AIO_NUM);
    cms->update(analog_pn_dev_input, ZUCMOT_PNDev_INT_AIO_NUM + ZUCMOT_PNDev_FLOAT_AIO_NUM);
    cms->update(analog_eip_adpt_input, ZUCMOT_EIP_INT_AIO_NUM + ZUCMOT_EIP_FLOAT_AIO_NUM);

    cms->update(analog_mb_slave_output, ZUCMOT_MAX_MODBUS_AIO_NUM);
    cms->update(analog_pn_dev_output, ZUCMOT_PNDev_INT_AIO_NUM + ZUCMOT_PNDev_FLOAT_AIO_NUM);
    cms->update(analog_eip_adpt_output, ZUCMOT_EIP_INT_AIO_NUM + ZUCMOT_EIP_FLOAT_AIO_NUM);

    cms->update(profinet_state);
    cms->update(eip_state);
    cms->update(eip_di_num);
    cms->update(eip_do_num);
    cms->update(eip_ai_int_num);
    cms->update(eip_ai_float_num);
    cms->update(eip_ao_int_num);
    cms->update(eip_ao_float_num);
    //cms->update(appver);
    cms->update(di_type_pin_g1);
    cms->update(di_type_pin_g2);
    cms->update(do_type_pin_g1);
    cms->update(do_type_pin_g2);

    cms->update(scb_anachn_setting);
    cms->update(scb_digchn_setting);
    FuncIOMap_update(cms, &funcIOMap);
    FuncIOReq_update(cms, &func_io_req);
    UhiData_update(cms, &uhiData);
}